package com.lnsf.bookstore.system.advertise.controller;

import com.github.pagehelper.PageInfo;
import com.lnsf.bookstore.common.annotation.SysLog;
import com.lnsf.bookstore.common.dto.ResultSuccessDto;
import com.lnsf.bookstore.system.advPosition.vo.AdvPosition;
import com.lnsf.bookstore.system.advertise.service.AdvertiseService;
import com.lnsf.bookstore.system.advertise.vo.Advertise;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/adverise")
public class AdvertiseController {

    @Autowired
    private AdvertiseService advertiseService;


    @RequestMapping("/v_list.do")
    public String list(){
        return "admin/adverise/adverise";
    }

    /**
     * 查看所有列表
     */
    @SysLog("查看广告位置列表")
    @RequestMapping("/queryAll")
    @ResponseBody
    public Object queryAll(@RequestParam Map<String, Object> params, Advertise advertise) {
        PageInfo<Advertise> pageInfo = advertiseService.selectAll(params , advertise);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("page",pageInfo);
        return map;
    }

    /**
     * 修改、新增操作
     */
    @SysLog("修改/新增")
    @RequestMapping(value = "/saveOrUpdate", method = RequestMethod.POST)
    @ResponseBody
    public Object saveOrUpdate(HttpServletRequest request, Integer id , @RequestBody Advertise advertise, ModelMap modelMap){
        if(advertise.getAdvId()==null){//新增
            //verifyForm(category);
            advertiseService.save(advertise);
        }else{//修改
            //verifyForm(category);
            advertiseService.update(advertise);
        }
        return new ResultSuccessDto("操作成功");
    }


    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    @ResponseBody
    @SysLog("查看广告位置信息")
    public Object info(@PathVariable("id") Integer id) {
        Advertise advertise = advertiseService.queryObject(id);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("advertise",advertise);
        return map;
    }
}
